home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 15 / Example 15.1 / network.h < prev   
Encoding:
C/C++ Source or Header  |  2006-06-30  |  1.4 KB  |  46 lines

  1. #ifndef _RTS_NETWORK_
  2. #define _RTS_NETWORK_
  3.  
  4. #include <windows.h>
  5. #include <dplay8.h>     // directplay
  6. #include <vector>
  7. #include "debug.h"
  8. #include "network_messages.h"
  9.  
  10. class NETWORK
  11. {
  12.     friend HRESULT WINAPI ServerCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  13.     friend HRESULT WINAPI ClientCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  14.     public:
  15.         NETWORK();
  16.         ~NETWORK();
  17.  
  18.         void Init(bool _server, char _playerName[]);
  19.         void Release();
  20.         void HostNewSession(char sessionName[]);
  21.         void FindSessions();                    //Enumerate all available sessions
  22.         HRESULT ConnectToSession(int index);
  23.         DP_PLAYER *FindPlayer(DPNID id);
  24.         void Send(RTS_MSG *msg);                //Send to all (or server)
  25.         void SendTo(DPNID id, RTS_MSG *msg);    //Send To specific player 
  26.         
  27.         //Public Variables
  28.         bool server, connected;
  29.         char playerName[64];                //Name of local player
  30.         char activeSession[50];                //name of active session
  31.         std::vector<SESSION> sessions;
  32.         std::vector<DP_PLAYER> players;
  33.         std::vector<std::string> chat;
  34.  
  35.     private:
  36.         IDirectPlay8Server *m_pServer;
  37.         IDirectPlay8Client *m_pClient;
  38.         IDirectPlay8Address *m_pMyAddress, *m_pServerAddress;
  39.         DPNID m_localID;
  40. };
  41.  
  42. //Network callback functions
  43. HRESULT WINAPI ServerCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  44. HRESULT WINAPI ClientCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  45.  
  46. #endif